<?php
namespace app\admin\controller;
use think\console\Input;

use think\Request;

use think\Controller;
use think\Db;
class Role extends Controller
{
public function role()
   {
   	$list=Db::name("jf_role")
   	        ->paginate(2);
            
            $page = $list->render();

            $this->assign('list',$list);
            $this->assign('page', $page);
      return $this->fetch();

   }
   public function role_add()
   {
   	  $request=Request::instance();
   	  if($request->has('sub','post'))
   	  {
   	     
   	     $r_role=$request->post('r_role');
   	      	     
   	     $data=[
   	           
   	           'r_role'=>$r_role,
   	                    
   	     ];
   	   $result=Db::table('jf_role')->insert($data);
   	   if($result)
   	   {
   	      $this->success('新增成功','Role/role');
   	   }
   	   else 
   	   {
   	      $this->error('新增失败');
   	   }
   	  }
   	  else 
   	  {
   	     $r_id=input('?param.r_id');
   	     $jf_role=Db::table('jf_role')->where('r_id',$r_id)->find();
   	     return $this->fetch('role_add',[
   	                             'jf_role'=>$jf_role
   	         ]);
   	  }
      //return $this->fetch(); 
   }
   public function role_update()
   {
    
   	$request=Request::instance();
  	if ($request->has("sub","post"))
  	{
	     $r_id=$request->param("r_id");
	     $r_role=$request->post('r_role');  
	  	 $data=[
	  	       'r_id'=>$r_id,   	           
   	           'r_role'=>$r_role,	           
   	      ]; 	  	    
	     $result=Db::table("jf_role")
		         ->update($data);
	  	if($result)
		  {$this->success("修改成功","Role/role");}
	    else 
		  {$this->error("修改失败");}
	  	}
  	else 
  	{
	  	$r_id=$request->param("r_id");
	  	$data=['r_id'=>$r_id];  
		$list=Db::name("jf_role")
			  ->where('r_id',$r_id)
	          ->find();
	     return $this->fetch('role_update',[
               'list'=>$list,
       ]);        
  	}
   }
   public function role_delete()
   {
      $request=Request::instance();
      $r_id=$request->param('r_id');
      $data=['r_id'=>$r_id];
      $result=Db::table('jf_role')->delete($data);
       if($result)
      {
        $this->success('删除成功','Role/role');  
      }
      else 
      {
        $this->error('删除失败');
      }
      
   }
}

